package com.qingzhu.dao.impl;

import com.qingzhu.dao.OrderItemDao;
import com.qingzhu.pojo.OrderItem;
import com.qingzhu.util.CreateSqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OrderItemDaoImpl implements OrderItemDao {

    @Override
    public int insterOrderItem(OrderItem orderItem) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderItemDao orderItemDao = sqlSession.getMapper(OrderItemDao.class);
            int result = orderItemDao.insterOrderItem(orderItem);
            return result;
        }
    }

    @Override
    public List<OrderItem> findOrderItemByOrderId(int orderId) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderItemDao orderItemDao = sqlSession.getMapper(OrderItemDao.class);
            return orderItemDao.findOrderItemByOrderId(orderId);
        }
    }

    @Override
    public List<OrderItem> findOrderItemByKey(String searchInput) {
        try (SqlSession sqlSession = CreateSqlSessionFactory.getFactory().openSession(true)) {
            OrderItemDao orderItemDao = sqlSession.getMapper(OrderItemDao.class);
            return orderItemDao.findOrderItemByKey(searchInput);
        }
    }

}
